﻿
Partial Class App_Test_CorB
    Inherits MyUI.PageBaseApp


    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

        Response.BufferOutput = False

        Dim AccountID = 1 ' 32656
        Dim Acc = DB.TAB.Account.GetByPK(AccountID)

        Dim AD = mDB.Archive_Simil_Text.GetArchive(mDB.Archive_Simil_Text.ArchiveType.POST_FOLLOWERS, Acc.Id).GetSimilTextArchiveData

        Dim Folls = Acc._Tab_Account_Link(mDB._Account_Link.Type.FOLLOWER).
            REL._Account_Link.Account.
            ToList(Of mDB.Account)()

        Dim Ccont = 0
        Dim Bcont = 0
        'Dim Cword = {"io", "tu", "mio", "suo", "sono", "sei", "ho", "hai"}
        'Dim Bword = {"noi", "voi", "nostro", "vostro", "siamo", "siete", "abbiamo", "avete"}

        Dim Cword = {"% io %", "% mio %", "% mie %", "% miei %", "% sono %", "% ho %", " %isco %"}
        'Dim Bword = {"% noi %", "% nostro %", "% nostre %", "% nostri %", "% siamo %", "% abbiamo %", " %iamo %"}
        Dim Bword = {"noi", "nostro", "nostre", "nostri", "siamo", "abbiamo"}


        ' scorro i followers
        For Each f In Folls


            Dim posts = f._Tab_Account_Post.Limit(400).ToList

            'scorro i post
            For Each p In posts


                Dim words = SimilText.TextTools.TextToWord(p.Post_Text)

                'scorro le parole dei post

                For Each w In words
                    If AD.Stemming.Words.ContainsKey(w) Then

                        Dim i = AD.Stemming.Words(w)
                        Dim der = AD.Stemming.WordsList(i).StemmingIds.Select(Function(o) AD.Stemming.WordsList(o).Word).ToArray

                        If Me.controllaverbo(der, w, "isco", "ire") Then
                            Ccont += 1
                        ElseIf Me.controllaverbo(der, w, "o", "are") Then
                            Ccont += 1
                        ElseIf Me.controllaverbo(der, w, "o", "ere") Then
                            Ccont += 1
                        ElseIf Me.controllaverbo(der, w, "o", "ire") Then
                            Ccont += 1
                        End If

                        If Me.controllaverbo(der, w, "iamo", "are") Then
                            Bcont += 1
                        ElseIf Me.controllaverbo(der, w, "iamo", "ere") Then
                            Bcont += 1
                        ElseIf Me.controllaverbo(der, w, "iamo", "ire") Then
                            Bcont += 1
                        End If

                        For Each s In Bword
                            If s = w Then
                                Bcont += 1
                                Exit For
                            End If

                        Next


                    End If

                Next

            Next


            Dim res = IIf(Utils.Math.Div(Bcont, posts.Count) >= 0.089999999999999997, "BUSS", "CONS")

            UI.Page.WriteLog(SF(";{0};{1};{2};{3};{4}", res, posts.Count, Bcont, f.Fullname, f.Description))

            Ccont = 0
            Bcont = 0

        Next

    End Sub

    Function controllaverbo(der() As String, parola As String, fine As String, coniu As String) As Boolean

        If parola.EndsWith(fine) Then

            Dim p = Regex.Replace(parola, fine & "$", coniu)

            Return der.Where(Function(o) o = p).ToArray.Length > 0

        Else
            Return False
        End If



    End Function



    Protected Sub analisi1()

        Response.BufferOutput = False

        Dim AccountID = 1 ' 32656
        Dim Acc = DB.TAB.Account.GetByPK(AccountID)


        Dim Folls = Acc._Tab_Account_Link(mDB._Account_Link.Type.FOLLOWER).REL._Account_Link.Account.
            ToList(Of mDB.Account)()

        Dim Ccont = 0
        Dim Bcont = 0
        'Dim Cword = {"io", "tu", "mio", "suo", "sono", "sei", "ho", "hai"}
        'Dim Bword = {"noi", "voi", "nostro", "vostro", "siamo", "siete", "abbiamo", "avete"}

        Dim Cword = {"% io %", "% mio %", "% mie %", "% miei %", "% sono %", "% ho %", " %isco %"}
        Dim Bword = {"% noi %", "% nostro %", "% nostre %", "% nostri %", "% siamo %", "% abbiamo %", " %iamo %"}


        For Each f In Folls

            For Each s In Cword
                Ccont += f._Tab_Account_Post.
                    Where("CONCAT(' ',post_text,' ')", "like", s).SetSelect("count(*) as tot").
                ToObj(Of Integer)()

            Next

            For Each s In Bword
                Bcont += f._Tab_Account_Post.
                    Where("CONCAT(' ',post_text,' ')", "like", s).SetSelect("count(*) as tot").
                ToObj(Of Integer)()

            Next

            Dim res = IIf(Utils.Math.Div(Bcont, Ccont) > 0.5, "BUSS", "CONS")

            UI.Page.WriteLog(SF(";{4};{0};{3};{1};{2}", f.Fullname, Ccont, Bcont, f.Description, res))

            Ccont = 0
            Bcont = 0

        Next







    End Sub

End Class
